package com.tourism.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tourism.dao.AttractionOrderDao;
import com.tourism.entity.AttractionOrder;
import com.tourism.entity.AttractionOrderQuery;
import com.tourism.entity.OrderPayInfo;
import com.tourism.service.AttractionOrderService;
import com.tourism.util.SystemHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author z
 * @Date 2021-05-01 9:16
 */
@Service
public class AttractionOrderServiceImpl implements AttractionOrderService {
    @Autowired
    private AttractionOrderDao attractionOrderDao;

    @Override
    public boolean addAttractionOrder(AttractionOrder attractionOrder) {
        attractionOrder.setOrderUser(SystemHelper.getUserId());
        attractionOrder.init();
        return attractionOrderDao.addAttractionOrder(attractionOrder);
    }

    @Override
    public AttractionOrder getAttractionOrderById(Long id) {
        return attractionOrderDao.getAttractionOrderById(id);
    }
//删除订单
    @Override
    public Boolean deleteAttractionOrderById(Long id) {
        return attractionOrderDao.deleteAttractionOrderById(id);
    }

    @Override
    public PageInfo<AttractionOrder> getAttractionOrderList(AttractionOrderQuery query) {
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        //判断是否是管理员（管理员查询所有，否之用户只能查询自己的）
        if (!SystemHelper.isAdmin()) {
            query.setOrderUser(SystemHelper.getCurrentUser().getId());
        }
        List<AttractionOrder> CustomLineList = attractionOrderDao.getAttractionOrderList(query);
        PageInfo<AttractionOrder> result = new PageInfo<>(CustomLineList);
        return result;
    }

    @Override
    public boolean updateOrderPayInfo(OrderPayInfo orderPayInfo) {
        orderPayInfo.init();
        return attractionOrderDao.updateOrderPayInfo(orderPayInfo);
    }

}
